package com.ruoyi.web.controller.app;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.common.utils.tencentUtils.TencentCloudImUtil;
import com.ruoyi.system.domain.AppUser;
import com.ruoyi.system.service.IAppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 二期由腾讯IM转为网易云信IM，相关接口修改重写
 */
@RestController
@RequestMapping("app/neteaseUser")
@Api("用户接口")
public class ForAppNeteaseUserController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private IAppUserService userService;

    @Autowired
    private TencentCloudImUtil tencentCloudImUtil;

    @PostMapping("editUserInfo")
    @ApiOperation("编辑用户信息")
    public AjaxResult editUserInfo(@ApiParam("头像Url") String headImgUrl,
                                   @ApiParam("昵称") String nickName,
                                   @ApiParam("性别，0：未知，1：男性，2：女性") Integer sex,
                                   @ApiParam("朋友圈背景图") String backImgUrl,
                                   @ApiParam("用户签名") String sign) {
        if (StringUtils.isBlank(headImgUrl) && StringUtils.isBlank(nickName) && sex == null && StringUtils.isBlank(backImgUrl) && StringUtils.isBlank(sign)) {
            return AjaxResult.error(-1, "参数不能为空");
        }
        System.out.println("昵称:" + nickName);
        System.out.println("性别:" + sex);
        System.out.println("用户签名:" + backImgUrl);
        System.out.println("头像Url:" + headImgUrl);
        AppUser user = new AppUser();
        user.setUserId(getUserId());
        user.setHeadImg(headImgUrl);
        user.setUsername(nickName);
        user.setSex(sex);
        user.setBackImg(backImgUrl);
        user.setSign(sign);
        // 同步腾讯云信息
        tencentCloudImUtil.updataUserInfo(getUserId() + "", headImgUrl, nickName, sex, sign);
        return userService.editUserInfo(user);
    }


}
